package cn.shutdown.demo.jvm;

/**
 * -Xms 初始堆  -Xmx 最大堆 参数测试
 * -Xmx20m -Xms5m -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -XX:+UseSerialGC
 * @author jiangwujie
 * @date 2021/6/7
 */
public class HeapAlloc {

    public static void main(String[] args) {

        printMemory("");
        //分配1M内存
        byte[] b = new byte[1 * 1024 * 1024];
        printMemory("分配了1M内存");
        //分配4M内存
        b = new byte[4 * 1024 * 1024];
        printMemory("分配了4M内存");
    }

    static void printMemory(String step) {
        System.out.println(step);
        System.out.println("maxMemory=" + Runtime.getRuntime().maxMemory() + " bytes");
        System.out.println("freeMemory=" + Runtime.getRuntime().freeMemory() + " bytes");
        System.out.println("toatlMemory=" + Runtime.getRuntime().totalMemory() + " bytes");
    }

}
